#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <string.h>

#include "anytimer.h"

/*
 * 定时执行任务
 * */
static void task1(void *arg)
{
	printf("task1 is invoked : %s \n", (char *)arg);
}

static void task2(void *arg)
{
	printf("task2 is invoked : %s \n", (char *)arg);
}

static void task3(void *arg)
{
	printf("task3 is invoked : %s \n", (char *)arg);
}

int main(int argc, char **argv)
{
	int job1, job2, job3;

	puts("start---------------------\n");

	job1 = add_job(7,task1,"aaa");
	if(job1 < 0){
		fprintf(stderr, "at_addjob(1): %s\n", strerror(-job1));
	}

	job2 = add_job(2,task2,"bbb");
	if(job2 < 0){
		fprintf(stderr, "at_addjob(2): %s\n", strerror(-job2));
	}

	job3 = add_job(5,task3,"ccc");
	if(job3 < 0){
		fprintf(stderr, "at_addjob(3): %s\n", strerror(-job3));
	}

	puts("end---------------------\n");

    while(1) {
        write(1, ".", 1);
        pause();
        at_wait_job(job1);
        at_wait_job(job2);
        at_wait_job(job3);
    }

	exit(0);
}
